home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / ddj0492.zip / DFLT11.ZIP / DFALLOC.C < prev    next >
Text File  |  1992-01-27  |  1KB  |  76 lines

  1. /* ---------- dfalloc.c ---------- */
  2.  
  3. #include "dflat.h"
  4.  
  5. #undef malloc
  6. #undef calloc
  7. #undef realloc
  8.  
  9. static void AllocationError(void)
  10. {
  11.     WINDOW wnd;
  12.     static BOOL OnceIn = FALSE;
  13.     extern jmp_buf AllocError;
  14.     extern BOOL AllocTesting;
  15.     static char *ErrMsg[] = {
  16.         "┌────────────────┐",
  17.         "│ Out of Memory! │",
  18.         "└────────────────┘"
  19.     };
  20.     int x, y;
  21.     char savbuf[108];
  22.     RECT rc = {30,11,47,13};
  23.  
  24.     if (!OnceIn)    {
  25.         OnceIn = TRUE;
  26.         /* ------ close all windows ------ */
  27.         wnd = Focus.FirstWindow;
  28.         while (wnd != NULL)    {
  29.             if (GetClass(wnd) == APPLICATION)    {
  30.                 SendMessage(wnd, CLOSE_WINDOW, 0, 0);
  31.                 break;
  32.             }
  33.             wnd = NextWindow(wnd);
  34.         }
  35.         getvideo(rc, savbuf);
  36.         for (x = 0; x < 18; x++)    {
  37.             for (y = 0; y < 3; y++)        {
  38.                 int c = (255 & (*(*(ErrMsg+y)+x))) | 0x7000;
  39.                 PutVideoChar(x+rc.lf, y+rc.tp, c);
  40.             }
  41.         }
  42.         getkey();
  43.         storevideo(rc, savbuf);
  44.         if (AllocTesting)
  45.             longjmp(AllocError, 1);
  46.     }
  47. }
  48.  
  49. void *DFcalloc(size_t nitems, size_t size)
  50. {
  51.     void *rtn = calloc(nitems, size);
  52.     if (size && rtn == NULL)
  53.         AllocationError();
  54.     return rtn;
  55. }
  56.  
  57. void *DFmalloc(size_t size)
  58. {
  59.     void far * rtn = malloc(size);
  60.     if (size && rtn == NULL)
  61.         AllocationError();
  62.     return rtn;
  63. }
  64.  
  65. void *DFrealloc(void far *block, size_t size)
  66. {
  67.     void far * rtn = realloc(block, size);
  68.     if (size && rtn == NULL)
  69.         AllocationError();
  70.     return rtn;
  71. }
  72.  
  73.  
  74.  
  75.  
  76.